package com.yq.homework.day30.udp1;

import com.sun.java.swing.plaf.windows.WindowsInternalFrameTitlePane;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 20:11
 */
public class SendInfo  implements Runnable{
    DatagramSocket socket;

    String ip;
    int port;

    public SendInfo(DatagramSocket socket, String ip, int port) {
        this.socket = socket;
        this.ip = ip;
        this.port = port;
    }

    @Override
    public void run() {
        Scanner scanner = new Scanner(System.in);
        //只发送数据
        while (true){
            String s = scanner.nextLine();
            try {
                DatagramPacket sendPacket = NetUtils.getSendPacket(s, ip, port);
                socket.send(sendPacket);
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
}
